Add a Fair lock recipe?#115
Conversation
|
The tricky part is what to do when one of the cache key expires but not both of them. Maybe there needs to be a single cache key to track tickets and serving. It still seems the cache key could expire while someone is holding the lock. I'm not sure how they later discover that the lock was lost. I'm sure there's research on this problem. Need to look there rather than re-implementing. |
|
Brainstorming, came up with: But I think this'll break because the current ticket number is only incremented by release(). If one of the release() calls doesn't happen, then everything will be stuck. |
|
Change the code such that if the lock expires then it is immediately reacquired by another thread or process in the acquire() method rather than by first releasing it. Update the release ticket code to set time correctly. This will allow the acquire method to skip tickets if they are not acquired after a long time. |
|
When first acquiring a ticket, if the pid_tid already holds the lock, then don't increment the tickets count. |
Some prototyping for a fair lock recipe.